#! /bin/bash

# Reading obj files form directory ./obj/ and
# store sample points into ./data/
# chmod +x setdb
# bash setdb || sh setdb || ./setdb

if [ ! -f 'vse_main' ];
then
	echo "ERROR: Please compile vse_main by \"make\" before using setdb"
	exit
fi

if [ "$#" -lt "2" ]; then
	echo "Usage: ./setdb [path] [0 or 1 (0->negative, 1->positive)]"
	exit
fi

SP="-v"

if [ "$#" -eq 3 ]; then
	if [ "$3" != "-v" ]; then
		SP='-rt'
	fi
fi

if [ "$2" -eq 1 ]; then
	echo "** These samples will be stored in positive.txt"
else
	echo "** These samples will not be stored in positive.txt"
fi

CNT=0

echo "========================================"
echo "====== Setting up the database... ======"
echo "========================================"

#find $1 -name '*.obj' -exec ./vse_main '-a' {} \;

for file in `find $1 -name '*.obj'`; do
	./vse_main '-a' $file "$SP"
	CNT=$((CNT+1))
	if [ "$2" -eq 1 ]; then
		echo $file >> positive.txt
	fi
done

echo "========================================"
echo "======== $CNT obj files are added! ========"
echo "========================================"

exit 0
